package org.september.pisces.user.permission.service;

import java.util.Date;

import org.september.pisces.user.permission.entity.SystemRole;
import org.september.pisces.user.permission.utils.UserSessionHelper;
import org.september.smartdao.CommonDao;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SystemRoleService {
	
	@Autowired
	private CommonDao dao;
	
	@Autowired
	private OperationLogService operationLogService;
	
	@Autowired
	private PiscesPermissionService piscesPermissionService;
	
	@Transactional
	public void cloneRole(SystemRole po) {
		SystemRole newRole = new SystemRole();
		BeanUtils.copyProperties(po, newRole);
		newRole.setName(po.getName()+"-副本");
		newRole.setId(null);
		newRole.setAddtime(new Date());
		newRole.setAdduid(UserSessionHelper.getLoginUid());
		newRole.setIsBuildIn(0);
		dao.save(newRole);
		piscesPermissionService.clonePermission(po.getId(), newRole.getId());
		operationLogService.addLog("克隆了角色【"+po.getName()+"】");
	}
	
}
